#!/usr/local/python/bin/python
# coding=utf-8
__author__ = 'Junjie.M'

import types
import random


class Util:
    # 获取随机数
    @staticmethod
    def getRandomNum(startNum, endNum):
        return random.randint(startNum, endNum)

    @staticmethod
    def isEmptyArray(arr):
        if arr == None:
            return True
        return len(arr) == 0

    # 判断是否null
    @staticmethod
    def isEmpty(str):
        if str == None:
            return True
        return len(str.strip()) == 0

    # 保持原字符串
    @staticmethod
    def decode(str):
        return str.decode('string-escape')

    # 判断一个字符串是否另外的字符
    @staticmethod
    def containStr(code1, code2):
        if code1 in code2:
            return True
        else:
            return False

    @staticmethod
    def sqlConvert(sql, vars):
        if Util.isEmptyArray(vars):
            return sql;
        var = list(vars)
        for key in var:
            if type(vars[key]) in (types.StringType,
                                   types.IntType, types.FloatType, types.LongType, types.BooleanType):
                sql = sql.replace('$' + key + '$', str(vars[key]))
        return sql;